﻿using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Koonsoft.HYCRM.DAL
{
    public class UtilityDAL
    {
        private static readonly Database database = DatabaseFactory.CreateDatabase("KOONCRMDB");

        /// <summary>
        /// 按照日期更新流水号并获取新流水号
        /// </summary>
        /// <param name="seqName">模块名称</param>
        /// <param name="length">流水号长度（包括0）</param>
        /// <param name="currDate">流水号日期</param>
        /// <returns></returns>
        public string GetRegularDateVal(string seqName, int length, string currDate)
        {
            const string sql = "Utility_GetRegularDateVal";

            using (var cmd = database.GetStoredProcCommand(sql))
            {
                database.AddInParameter(cmd, "seqname", DbType.String, seqName);
                database.AddInParameter(cmd, "length", DbType.Int32, length);
                database.AddInParameter(cmd, "currDate", DbType.String, currDate);
                database.AddOutParameter(cmd, "RegularVal", DbType.String, 50);
                database.ExecuteNonQuery(cmd);

                return cmd.Parameters["@RegularVal"].Value.ToString();
            }
        }
    }
}
